package com.example.sys.ai.controller;

import com.example.core.utils.Result;
import com.example.sys.ai.dto.Company;
import com.example.sys.ai.service.SysTianYanChaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class SysTianYanChaController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private SysTianYanChaService sysTianYanChaService;

    /***
     * 获取公司信息通过公司id
     * @param companyId
     * @return
     */
    @GetMapping(value = "getCompanyById")
    public Result getCompanyById(String companyId) {
        try {
            Company company = sysTianYanChaService.getByCompany(companyId);
            return Result.success(company);
        } catch (Exception e) {
            logger.warn("getCompanyById error :" + e.getMessage());
            return Result.error(e.getMessage());
        }
    }

    /***
     * 关键字搜索公司列表信息
     * @param keyWord
     * @return
     */
    @GetMapping(value = "getByCompanyList")
    public Result getByCompanyList(String keyWord) {
        try {
            List<Company> list = sysTianYanChaService.getByCompanyList(keyWord);
            return Result.success(list);
        } catch (Exception e) {
            logger.warn("getCompanyById error :" + e.getMessage());
            return Result.error(e.getMessage());
        }
    }
}
